package cn.edu.jnu.x2022103548;



import androidx.test.ext.junit.rules.ActivityScenarioRule;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.*;
import static androidx.test.espresso.assertion.ViewAssertions.*;
import static androidx.test.espresso.matcher.ViewMatchers.*;

@RunWith(AndroidJUnit4.class)
public class MainActivityTest {
    @Rule
    public ActivityScenarioRule<MainActivity> activityRule =
            new ActivityScenarioRule<>(MainActivity.class);

    @Test
    public void testUIInteraction() {
        // 测试输入5分
        onView(withId(R.id.rollInput)).perform(typeText("5"));
        onView(withId(R.id.rollButton)).perform(click());

        onView(withId(R.id.scoreText)).check(matches(withText("当前得分: 5")));

        // 测试输入3分
        onView(withId(R.id.rollInput)).perform(typeText("3"), closeSoftKeyboard());
        onView(withId(R.id.rollButton)).perform(click());
        onView(withId(R.id.scoreText)).check(matches(withText("当前得分: 8")));
    }
}